//
//  QDSDHeziCycleViewTableViewCell.m
//  QDMetroClient
//
//  Created by YueWen on 2019/4/15.
//  Copyright © 2019 YueWen. All rights reserved.
//

#import "QDHDHZCycleViewTableViewCell.h"
#import "QDMetroClient-Swift.h"


NSString *QDSDCycleHZCellKey = @"QDSDCycleHZCellKey";
NSString *QDSDCycleNormalCellKey = @"QDSDCycleNormalCellKey";


@implementation QDHDHZCycleViewTableViewCell

#pragma mark - 活动盒子的数据源

- (NSDictionary<NSString *,Class> *)cycleViewAllRegisterCellClasses:(RITLSDCycleScrollView *)cycleView {
    
    return @{QDSDCycleHZCellKey: QDHeziCycleCollectionViewCell.class,
             QDSDCycleNormalCellKey: SDCollectionViewCell.class};
}



- (NSString *)cycleViewIdentifer:(RITLSDCycleScrollView *)cycleView atIndexPath:(NSIndexPath *)indexPath {
    
    if (!self.configCellIdentifierHandler) return QDSDCycleNormalCellKey;
    return self.configCellIdentifierHandler(cycleView,indexPath);
}



#pragma mark - copy from QDSDCycleViewPageTableViewCell


- (UICollectionViewFlowLayout *)customFlowLayout:(RITLCollectionViewPageFlowLayout *)originFlowLayout {
    return originFlowLayout;
}

#pragma mark - <RITLSDCycleScrollViewDataSource>

- (UICollectionViewLayout *)cycleScollViewcustomCollectionViewLayout:(RITLSDCycleScrollView *)cycleView {
    
    RITLCollectionViewPageFlowLayout *flowLayout = RITLCollectionViewPageFlowLayout.new;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 20, 0, 20);
    flowLayout.minimumLineSpacing = 10;
    flowLayout.minimumInteritemSpacing = CGFLOAT_MIN;
    
    // 计算item的Size
    CGFloat scale = 160.0 / 335;
    CGFloat itemWidth = UIScreen.mainScreen.ritl_width - 20 - 20;
    flowLayout.itemSize = CGSizeMake(itemWidth, itemWidth * scale);
    
    UICollectionViewLayout *customFlowLayout = [self customFlowLayout:flowLayout];
    
    self.flowLayout =[customFlowLayout isKindOfClass:RITLCollectionViewPageFlowLayout.class] ? (RITLCollectionViewPageFlowLayout *)customFlowLayout : nil;
    
    return flowLayout;
}


- (BOOL)cycleViewShouldResetCollectionWithCustomScrollPosition:(RITLSDCycleScrollView *)cycleView {
    return true;
}


- (UICollectionViewScrollPosition)cycleViewCustomCollectionViewScrollPosition:(RITLSDCycleScrollView *)cycleView {
    return UICollectionViewScrollPositionCenteredHorizontally;
}


- (NSInteger)cycleView:(RITLSDCycleScrollView *)cycleView currentIndexWithContentOffset:(CGPoint)contentOffset {
    return [self.flowLayout itemAtIndexPathForCollectionWithContentOffsetX:contentOffset.x];
}


@end
